import {NativeModules} from 'react-native';
const {SIDModule} = NativeModules;

export default class SID {

    //Initializer
    static initialize(
        clientId: string,
        partnerName?: string,
        themeColorLight?: string,
        themeColorDark?: string,
        partnerProfileUrl?: string,
        isShowErrorOnMain?: Boolean,
        standType?: SID_STAND
    ) {
        SIDModule.initialize(
            clientId,
            partnerName,
            themeColorLight,
            themeColorDark,
            partnerProfileUrl,
            isShowErrorOnMain,
            standType
        );
    }

    static auth(
        scope: string,
        state: string,
        nonce: string,
        redirectUri: string,
        ssoBaseUrl?: string,
        codeChallenge?: string,
        codeChallengeMethod?: string,
        loginHint?: string
    ) {
        SIDModule.auth(
            scope,
            state,
            nonce,
            redirectUri,
            ssoBaseUrl,
            codeChallenge,
            codeChallengeMethod,
            loginHint
        )
    }

    static loginWithIDWeb(
        scope: string,
        state: string,
        nonce: string,
        redirectUri: string,
        svcRedirectUrlString: string,
        ssoBaseUrl?: string,
        codeChallenge?: string,
        codeChallengeMethod?: string,
        loginHint?: string,
        callback?: (msg: boolean) => void
    ) {
        SIDModule.loginWithIDWeb(
            scope,
            state,
            nonce,
            redirectUri,
            ssoBaseUrl,
            codeChallenge,
            codeChallengeMethod,
            loginHint,
            svcRedirectUrlString,
            callback
        )
    }

    static logout() {
        SIDModule.logout();
    }

    static autoAuth(
        scope: string,
        state: string,
        nonce: string,
        redirectUri: string,
        ssoBaseUrl?: string,
        codeChallenge?: string,
        codeChallengeMethod?: string,
        loginHint?: string,
        callback?: (msg: boolean) => void
    ) {
        SIDModule.autoAuth(
            scope,
            state,
            nonce,
            redirectUri,
            ssoBaseUrl,
            codeChallenge,
            codeChallengeMethod,
            loginHint,
            callback
        );
    }

    static sendOtherAuth(
        nameAuthService: string,
        isSuccess: Boolean,
        isUserNew: Boolean
    ) {
        SIDModule.sendOtherAuth(
            nameAuthService,
            isSuccess,
            isUserNew
        )
    }

    static setUserID(userID: string) {
        SIDModule.setUserID(userID)
    }

    static setClientID(userID: string) {
        SIDModule.setClientID(userID)
    }

    //AppToken
    static updateAppToken(
        scope: string,
        clientId: string,
        state: string,
        nonce: string,
        redirectUri: string,
        codeChallenge?: string,
        codeChallengeMethod?: string,
        completion: (error: any, result: any) => void
    ) {
        SIDModule.updateAppToken(
            scope,
            clientId,
            state,
            nonce,
            redirectUri,
            codeChallenge,
            codeChallengeMethod,
            completion
        )
    }

    static checkAppTokenForValid(callback: (error: any, result: boolean) => void) {
        SIDModule.checkAppTokenForValid(callback)
    }

    static goToPartnerSSO(
        webLink: string,
        clientId?: string,
        partnerColor?: string,
        openIn?: SID_OPEN_IN_TYPE,
        callback: (error: any, result: any) => void,
    ) {
        SIDModule.goToPartnerSSO(
            webLink,
            clientId,
            partnerColor,
            openIn,
            callback
        )
    }

    static getIDAuthResult(
        deeplink: string,
        completion: (result: any) => void
    ) {
        SIDModule.getIDAuthResult(deeplink, completion)
    }

    //Android only
    static subscribeToAppTokenEvents(callback: (msg: any) => void) {
        SIDModule.subscribeToAppTokenEvents(callback)
    }

    //ELK (Android only)
    static subscribeToAnalytic(callback: (msg: any) => void){
        SIDModule.subscribeToAnalytic(callback)
    }

    static setUIMode(
        uiMode: COLOR_MODE = COLOR_MODE.AUTO,
        callback: (msg: any) => void
    ){
        SIDModule.setUIMode(mode)
    }

    static setCustomFonts(
        callback: (msg: any) => void,
        mediumResID?: number,
        semiBoldResID?: number,

    ){
        //Тут тоже могут быть вопросы
        SIDModule.setCustomFonts(mediumResID, semiBoldResID, callback)
    }
}

export enum COLOR_MODE {
    LIGHT = "light",
    DARK = "dark",
    AUTO = "auto"
}

export enum SID_STAND {
    PSI_CLOUD_STAND = "psi_cloud",
    PROM_STAND = "prom",
    PSI_STAND = "psi",
    IFT_STAND = "ift",
    IFT_CLOUD_STAND = "ift_cloud"
}

export enum SID_OPEN_IN_TYPE {
    WEBVIEW = "webview",
    BROWSER = "browser"
}
